﻿#include "stdafx.h"
#include "HomePageListCtl.h"
#include "ui_HomePageListCtl.h"

HomePageListCtl::HomePageListCtl(QWidget *parent)
: QWidget(parent), ui(new Ui::HomePageListCtl)
{
	ui->setupUi(this);
	pRecordTableModel = new QRecordTableModel;
	//pRecordTableModel->select("SELECT SHEETID,SHEETNAME FROM WS_SHEETINDEX WHERE SHEETTYPE = 1 AND SHEETTYPE <> 2 AND (SHEETSTATUSID=2 OR SHEETSTATUSID=3) AND (SHEETTYPE = 1 OR SHEETTYPE = 5) AND(SHEETSTATUSID=2 OR SHEETSTATUSID=3 OR SHEETSTATUSID=5 OR SHEETSTATUSID=6 OR SHEETSTATUSID=7 OR SHEETSTATUSID=8)  AND PATTERNID IN (SELECT PATTERNID FROM WS_PATTERNINFO WHERE MODULETYPE = 2)");
	pRecordTableModel->select("SELECT SHEETID,SHEETNAME,PAGENUM,DEPTNAME,MACHINE,MAKETIME,STATUSNAME FROM WS_SHEETINDEX WHERE SHEETTYPE = 1 AND SHEETTYPE <> 2 AND (SHEETSTATUSID=2 OR SHEETSTATUSID=3) AND (SHEETTYPE = 1 OR SHEETTYPE = 5)");
	
	pRecordTableModel->setCol(0, CF_PRIMARY, tr("sheetid"));
	pRecordTableModel->setCol(1, CF_SHOW, tr("sheetname"));
	pRecordTableModel->setCol(2, CF_SHOW, tr("PAGENUM"));
	pRecordTableModel->setCol(3, CF_SHOW, tr("DEPTNAME"));
	pRecordTableModel->setCol(4, CF_SHOW, tr("MACHINE"));
	pRecordTableModel->setCol(5, CF_SHOW, tr("MAKETIME"));
	pRecordTableModel->setCol(6, CF_SHOW, tr("STATUSNAME"));
	//ui->listView->setViewMode(QListView::IconMode);
	//ui->listView->setMovement(QListView::Static);
	//ui->listView->setIconSize(QSize(100, 100));
	//ui->listView->setGridSize(QSize(150, 130));
	//ui->listView->setGeometry(0, 0, 480, 272);
	//ui->listView->setResizeMode(QListView::Adjust);
	ui->tableView->setModel(pRecordTableModel);

	ui->tableView->setColumnWidth(0, 400);
	ui->tableView->setColumnWidth(1, 95);
	ui->tableView->setColumnWidth(2, 75);
	ui->tableView->setColumnWidth(3, 40);
	ui->tableView->setColumnWidth(4, 140);
	ui->tableView->setColumnWidth(5, 60);
	pRecordTableModel->refresh();

}

HomePageListCtl::~HomePageListCtl()
{

}

void HomePageListCtl::on_tableView_doubleClicked(const QModelIndex & index)
{
	if (index.isValid())
	{
		int row = index.row();

		int sheetID = pRecordTableModel->records().getCollectInt(row, "SHEETID");
		QString sheetName = pRecordTableModel->records().getCollectStr(row, "SHEETNAME");
		QString plantime = pRecordTableModel->records().getCollectStr(row, "PLANSTARTTIME");
		if (sheetID > 0)
			emit sheetListDoubleClicked(sheetID, 1, sheetName);

		//sheetID<=0弹出提醒
	}
}








